<!-- 页面外套 -->
<div class="page-wrapper" id="setup_business_suspend">

    <!-- 数据网格 -->
    <div class="datagrid datagrid-striped" id="setup_business_suspend_datagrid">

        <!-- 工具条组 -->
        <div class="tool-group">
            <div class="tool-search">
                <div class="im-label">
                    <div class="input-group">
                        <select class="form-control" id="setup_business_suspend_tool_keys">
                            <option value="1">姓名</option>
                            <option value="2">部门</option>
                        </select>
                        <span class="input-group-addon fix-border fix-padding"></span>
                        <input type="text" class="form-control" id="setup_business_suspend_tool_search">
                    </div>
                </div>
                <div class="im-label" id="setup_business_suspend_tool_date"><!--JS推进--></div>
                <label><button class="btn btn-primary" id="setup_business_suspend_search_btn"><i class="icon icon-search"></i> 搜索</button></label>
                <div class="clearfix"></div>
            </div>
            <div class="tool-deal">
                <label><button class="btn btn-primary" id="setup_business_suspend_add_btn"> <i class="icon icon-plus"></i> 添加暂停跟进</button></label>
                <label><button class="btn btn-primary" id="setup_business_suspend_restart_btn"> <i class="icon icon-repeat"></i> 批量重启跟进</button></label>
                <div class="clearfix"></div>
            </div>
        </div>
        <!-- tool-group -->

        <div class="datagrid-container"></div>
        <ul class="pager btn-mini" data-elements="prev,pages,next"></ul>
    </div>
    <!-- datagrid -->

    <!-- 添加盒子 -->
    <div class="modal modal-for-page fade" aria-hidden="false" id="setup_business_suspend_add_box">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">添加暂停跟进</h4>
                </div>
                <div class="modal-body">
                    <form class="container form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-2 required">暂停人员</label>
                            <div class="col-sm-8"><input type="text" class="form-control salesman_person_btn" id="setup_business_suspend_add_salesman" readonly></div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 required" for="setup_business_suspend_add_reason">暂停原因</label>
                            <div class="col-sm-8"><textarea class="form-control" id="setup_business_suspend_add_reason"></textarea></div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="setup_business_suspend_add_submit">提交</button>
                </div>                
            </div>
        </div>
    </div>
    <!-- setup_business_suspend_add_box -->

    <!-- 重启盒子 -->
    <div class="modal modal-for-page fade" aria-hidden="false" id="setup_business_suspend_restart_box">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">批量重启跟进</h4>
                </div>
                <div class="modal-body">
                    <p>确定重启员工：<strong class="text-primary"><!-- JS推进 --></strong> 的系统跟进倒计时吗？</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="setup_business_suspend_restart_submit">提交</button>
                </div>                
            </div>
        </div>
    </div>
    <!-- setup_business_suspend_restart_box -->

    <!-- 人员选择盒子 -->
    <div class="modal modal-for-page fade" aria-hidden="false" id="setup_business_suspend_salesman_box">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                    <h4 class="modal-title">商务专员选择</h4>
                </div>
                <div class="modal-body no-padding">

                    <!-- 数据网格 -->
                    <div class="datagrid datagrid-striped" id="setup_business_suspend_salesman_datagrid">

                        <!-- 工具条组 -->
                        <div class="tool-group no-padding">
                            <div class="tool-deal" style="border:none;">
                                <label>
                                    <span>姓名：</span>
                                    <input type="text" class="form-control" id="setup_business_suspend_salesman_user">
                                </label>
                                <label>
                                    <span>部门：</span>
                                    <select class="form-control" id="setup_business_suspend_salesman_depart"><!-- JS推进 --></select>
                                </label>
                                <label><button class="btn btn-primary" id="setup_business_suspend_salesman_search_btn">搜索</button></label>
                                <div class="clearfix"></div>
                            </div>
                        </div>
                        <!-- tool-group -->
                        <div class="datagrid-container"></div>
                        <ul class="pager btn-mini" data-elements="prev,pages,next"></ul>
                    </div>
                    <!-- datagrid -->

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="setup_business_suspend_salesman_submit">提交</button>
                </div>
            </div>
        </div>
    </div>
    <!-- setup_business_suspend_salesman_box -->

</div>
<!-- page-wrapper -->

<script>
$(function(){

//变量声明-----------------------------------------------------------------------------------------------
    var 
    setup_business_suspend                      = $("#setup_business_suspend"),                     //页面ID
    setup_business_suspend_datagrid             = $("#setup_business_suspend_datagrid"),            //数据表格
    //搜索
    setup_business_suspend_tool_keys            = $("#setup_business_suspend_tool_keys"),           //搜索类别
    setup_business_suspend_tool_search          = $("#setup_business_suspend_tool_search"),         //搜索字段
    setup_business_suspend_tool_date            = $("#setup_business_suspend_tool_date"),           //起止时间
    setup_business_suspend_search_btn           = $("#setup_business_suspend_search_btn"),          //搜索按钮
    //添加
    setup_business_suspend_add_btn              = $("#setup_business_suspend_add_btn"),             //添加按钮
    setup_business_suspend_add_box              = $("#setup_business_suspend_add_box"),             //添加盒子
    setup_business_suspend_add_submit           = $("#setup_business_suspend_add_submit"),          //添加提交
    setup_business_suspend_add_salesman         = $("#setup_business_suspend_add_salesman"),        //添加人员
    setup_business_suspend_add_reason           = $("#setup_business_suspend_add_reason"),          //添加原因
    //重启
    setup_business_suspend_restart_box          = $("#setup_business_suspend_restart_box"),         //重启盒子
    setup_business_suspend_restart_btn          = $("#setup_business_suspend_restart_btn"),         //重启按钮
    setup_business_suspend_restart_submit       = $("#setup_business_suspend_restart_submit"),      //重启提交
    //人员选择
    setup_business_suspend_salesman_box         = $("#setup_business_suspend_salesman_box"),        //人员选择盒子
    setup_business_suspend_salesman_submit      = $("#setup_business_suspend_salesman_submit"),     //人员选择提交
    setup_business_suspend_salesman_datagrid    = $("#setup_business_suspend_salesman_datagrid"),   //人员选择表格
    setup_business_suspend_salesman_user        = $("#setup_business_suspend_salesman_user"),       //人员选择姓名
    setup_business_suspend_salesman_depart      = $("#setup_business_suspend_salesman_depart"),     //人员选择部门
    setup_business_suspend_salesman_search_btn  = $("#setup_business_suspend_salesman_search_btn"); //人员选择搜索

    //接口对象-----------------------------------------------------------------------------------------------
    if( window.STATE == "local" ){

        //本地接口
        var setup_business_suspend_api = {
            datagrid            : LOCAL + "Test/test_datagrid.json",                                  //数据表格
            datagrid_salesman   : LOCAL + "Test/test_datagrid.json",                                  //人员选择表格
            select              : LOCAL + "Test/test_select.json",                                    //下拉选择
        }

    } else if ( window.STATE == "route" ){

        //远程接口
        var setup_business_suspend_api = {
            datagrid            : LOCAL + "Test/test_datagrid.json",                                  //数据表格
            datagrid_salesman   : LOCAL + "Test/test_datagrid.json",                                  //人员选择表格
            select              : LOCAL + "Test/test_select.json",                                    //下拉选择
        }

    }

    //数据表格-----------------------------------------------------------------------------------------------
    setup_business_suspend_datagrid.datagrid({
        height      : zui_datagrid_height(setup_business_suspend_datagrid),
        sortable    : false,
        cache       : false,
        showRowIndex: true,
        checkable   : true,
        checkByClickRow:false,
        selectable  : false,
        configs     : {
            R0:{className:"text-center"},
            C1:{className:"cell-hidden"}
        },
        states      : {
            pager           : {
                page        : 1,
                recPerPage  : window.REC_PER_PAGE,
            }
        },
        dataSource : {
            cols   : [
                {name:"id",        label:"ID",      width:49},
                {name:"name",      label:"姓名",	width:80},
                {name:"departname",label:"部门",	width:80},
                {name:"date",      label:"暂停时间",width:100},
                {name:"tex10",     label:"暂停原因",width:150}
            ],
            remote : function(){
                return {
                    url     : setup_business_suspend_api.datagrid,
                    type    : "POST",
                    dataType: "json",
                }
            }
        }
    });

    //变量声明-----------------------------------------------------------------------------------------------
    var setup_business_suspend_datagrid_obj = setup_business_suspend_datagrid.data("zui.datagrid");

    //时间组件-----------------------------------------------------------------------------------------------
    common_date_duration( setup_business_suspend_tool_date );
    setup_business_suspend_tool_date.find(".start").datetimepicker(option_date);
    setup_business_suspend_tool_date.find(".end").datetimepicker(option_date);
    
    //下拉选项-----------------------------------------------------------------------------------------------
    //人员选择-部门
    $.ajax({
        url     : setup_business_suspend_api.select,
        type    : "post",
        dataType: "json",
        data    : {},
        success : function(data){
            if( data.status>0 ){
                var data = data.data;
                var option = "<option value='0'>全部</option>";
                for(var i=0;i<data.length;i++){
                    option += "<option value='"+data[i].id+"'>"+data[i].name+"</option>"
                }
                setup_business_suspend_salesman_depart.html(option);
            }
        }
    });

    //搜索按钮-----------------------------------------------------------------------------------------------
    setup_business_suspend_search_btn.click(function(){

        //字段整理
        var keyword
        = "?sid="    + setup_business_suspend_tool_keys.val()
        + "&search=" + setup_business_suspend_tool_search.val()
        + "&date1="  + setup_business_suspend_tool_date.find(".start").val()
        + "&date2="  + setup_business_suspend_tool_date.find(".end").val();
        //GET提交
        zui_datagrid_render(setup_business_suspend_datagrid_obj,setup_business_suspend_api.datagrid+keyword);

    });
  
    //添加按钮-----------------------------------------------------------------------------------------------
    setup_business_suspend_add_btn.click(function(){
        
        //数据复原
        common_form_reset();

        //面板显示
        setup_business_suspend_add_box.modal("show");

    });
    //添加提交
    setup_business_suspend_add_submit.click(function(){

        //远程提交
        $.ajax({
            url     : API.test_response,
            type    : "post",
            dataType: "json",
            data    : {
                salesman : setup_business_suspend_add_salesman.attr("dataId"),
                reason : setup_business_suspend_add_reason.val()
            },
            success : function(data){
                if( data.status>0 ){
                    um_tip(data.message);
                    zui_datagrid_reset(setup_business_suspend_datagrid_obj,setup_business_suspend_api.datagrid,"clear");
                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });

    });

    //重启按钮-----------------------------------------------------------------------------------------------
    setup_business_suspend_restart_btn.click(function(){

        //数据复原
        common_form_reset();

        //批量取值
        var data_arr = setup_business_suspend_datagrid_obj.getCheckItems().filter(function(e){return e});
        if( data_arr.length>0 ){
            
            //ID获取
            var data_id = [];
            for(var i=0;i<data_arr.length;i++){
                data_id.push(data_arr[i].id);
            }

            //姓名获取
            var data_user = [];
            for(var u=0;u<data_arr.length;u++){
                data_user.push(data_arr[u].name);
            }

            //数据赋值
            setup_business_suspend_restart_box.find("strong").html(data_user.join(","));
            setup_business_suspend_restart_submit.attr("dataId",data_id.join(","));
     
            //面板显示
            setup_business_suspend_restart_box.modal("show");

        } else {
            um_tip("至少选择一条数据","1000","text-danger");
        }

    });
    //重启提交
    setup_business_suspend_restart_submit.click(function(){

        //ID取值
        var data_id = $(this).attr("dataId");

        //远程提交
        $.ajax({
            url     : API.test_response,
            type    : "post",
            dataType: "json",
            data    : { id : data_id },
            success : function(data){
                if( data.status>0 ){
                    um_tip(data.message);
                    zui_datagrid_reset(setup_business_suspend_datagrid_obj,setup_business_suspend_api.datagrid,"clear");
                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });

    });

    //人员选择------------------------------------------------------------------------------------------
    //数据列表
    setup_business_suspend_salesman_datagrid.datagrid({
        height      : 400,
        sortable    : false,
        cache       : false,
        showRowIndex: true,
        checkable   : true,
        selectable  : false,
        configs     : {
            R0:{className:"text-center"},
            C1:{className:"cell-hidden"}
        },
        states      : {
            pager           : {
                page        : 1,
                recPerPage  : window.REC_PER_PAGE,
            }
        },
        dataSource : {
            cols   : [
                {name:"id",label:"ID",  width:1 },
                {name:"name",label:"姓名",width:80 },
                {name:"departname",label:"部门",width:100},
                {name:"positionname",label:"职务"}
            ],
            remote : function(){
                return {
                    url     : setup_business_suspend_api.datagrid_salesman,
                    type    : "POST",
                    dataType: "json",
                }
            }
        }
    });
    var setup_business_suspend_salesman_datagrid_obj = setup_business_suspend_salesman_datagrid.data("zui.datagrid");

    //搜索按钮
    setup_business_suspend_salesman_search_btn.click(function(){

        //字段整理
        var keyword
        = "?search=" + setup_business_suspend_salesman_user.val()
        + "&depart=" + setup_business_suspend_salesman_depart.val();

        //GET提交
        zui_datagrid_render(setup_business_suspend_salesman_datagrid_obj,setup_business_suspend_api.datagrid_salesman+keyword);

    });
    //点击显示
    $(".salesman_person_btn").click(function(){

        //按钮ID获取
        COMMON_PERSON_BTNID = $(this).attr("id");

        //批量勾选去除
        var data_arr = setup_business_suspend_salesman_datagrid_obj.getCheckItems().filter(function(e){return e});
        for(var i=0;i<data_arr.length;i++){
            setup_business_suspend_salesman_datagrid_obj.checkRow(i,false);
        }

        //面板显示
        setup_business_suspend_salesman_box.modal("show");

    });
    //提交按钮
    setup_business_suspend_salesman_submit.click(function(){
        
        //批量取值
        var data_arr = setup_business_suspend_salesman_datagrid_obj.getCheckItems().filter(function(e){return e});
        
        //ID获取
        var data_id = [];
        for(var i=0;i<data_arr.length;i++){
            data_id.push(data_arr[i].id);
        }

        //姓名获取
        var data_user = [];
        for(var u=0;u<data_arr.length;u++){
            data_user.push(data_arr[u].name);
        }

        //数据赋值
        $("#"+COMMON_PERSON_BTNID).val(data_user.join(","));
        $("#"+COMMON_PERSON_BTNID).attr("dataId",data_id.join(","));

        //面板显示
        setup_business_suspend_salesman_box.modal("hide");

    });

});//预加载结尾
</script>